#include "Vector2f.h"
#include <math.h>
CVector2f::CVector2f(float p_x, float p_y)
{
	x = p_x;
	y = p_y;
}
CVector2f::CVector2f(void)
{
	x = 0;
	y = 0;
}

CVector2f::~CVector2f(void)
{
}

CVector2f CVector2f::operator+ (const CVector2f& v)const
{
	CVector2f result;
	result.x = x + v.x;
	result.y = y + v.y;
	return result;
}

CVector2f CVector2f::operator- (const CVector2f& v)const
{
	CVector2f result;
	result.x = x - v.x;
	result.y = y - v.y;
	return result;
}

bool CVector2f::operator != (const CVector2f& v)const
{
	if(x != v.x || y != v.y)
		return true;

	return false;
}

CVector2f CVector2f::operator* (float f)const
{
	return CVector2f(x*f, y*f);
}

bool CVector2f::operator== (const CVector2f& v)const
{
	if(x != v.x || y != v.y)
		return false;

	return true;
}

CVector2f CVector2f::rotate(const float angle)const
{
	float newX = cos(angle)*x - sin(angle)*y;
	float newY = cos(angle)*y + sin(angle)*x;

	return CVector2f(newX, newY);
}

void CVector2f::normalize()
{
	float n = getNorme();

	x = x/n;
	y = y/n;
}

float CVector2f::getNorme()const
{
	return sqrt(x*x+y*y);
}

float CVector2f::dot(const CVector2f& v)const
{
	return x*v.x+y*v.y;
}